<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button>来个好玩的</button>
    <button>下去吧</button>
    <hr>

    <div id="root"></div>

    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>

    <script type="text/babel">
        class App extends React.Component{
            state = {
                src: 'http://api.xiaohigh.com/video/random'
            }
            //render 方法  渲染, 挂载  
            render(){
                console.log('3-挂载中....');
                return <div>
                        <button onClick={this.update}>强制更新</button><br/>
                        <video src={this.state.src} onClick={this.change} controls={true} width="300"></video>
                    </div>
            }

            update = () => {
                // this.setState()
                this.state.src = 'http://api.xiaohigh.com/video/random?t='+Date.now();
                //强制更新
                this.forceUpdate();
            }

            //修改视频的 URL
            change =() => {
                this.setState({
                    src: 'http://api.xiaohigh.com/video/random?t='+Date.now()
                })
            }
            
            //should 应该  component 组件 update 更新
            // 组件应该要更新了
            shouldComponentUpdate(){
                console.log('1-组件应该要更新了');
                return false;
            }

            //component 组件 will 将要  update 更新
            // 组件将要更新了
            componentWillUpdate(){
                console.log('2-组件将要更新了');
            }
            
            //componentDidUpdate 
            // component 组件 did 完成  update 更新
            componentDidUpdate(){
                console.log('4-组件完成了更新...');
            }


        }

        //获取按钮
        let btns = document.querySelectorAll('button');
        //第一个按钮绑定单击事件
        btns[0].onclick = function(){
            ReactDOM.render(<App />, document.querySelector("#root"));
        }

        btns[1].onclick = function(){
            ReactDOM.unmountComponentAtNode(document.querySelector("#root"));
        }

    </script>
</body>
</html>